clear all
cd "data"

use canvasser_endline_baseline_clean_ismp2_phone.dta, replace

count

keep if t1_respondent == 1

count
tabstat days_between, s(p50)

gen t0_ideo_very_liberal = t0_ideology == 5
gen t0_ideo_liberal = t0_ideology == 4
gen t0_ideo_moderate = t0_ideology == 3
gen t0_ideo_conservative = t0_ideology == 2
gen t0_ideo_very_conservative = t0_ideology == 1

// Create Demographic Table
label var t0_age Age
label var t0_female Female
label var t0_latino Latino
label var t0_immigrant Immigrant
label var t0_ideo_very_liberal "Very Liberal"
label var t0_ideo_liberal Liberal
label var t0_ideo_moderate Moderate
label var t0_ideo_conservative Conservative
label var t0_ideo_very_conservative "Very Conservative"
label var t0_prior_campaign_experience "Prior Campaign Experience"
label var t0_canvassed_phase_one "Prior Perspective-Getting Experience"


eststo demos: quietly estpost summarize ///
    t0_age t0_female t0_latino t0_immigrant t0_ideo_very_liberal t0_ideo_liberal ///
	t0_ideo_moderate t0_ideo_conservative t0_ideo_very_conservative t0_prior_campaign_experience t0_canvassed_phase_one
	
	
esttab demos using ../output/immigration_phone_demos.tex, ///
	cells("mean(pattern(1 1 0) fmt(2)) sd(pattern(1 1 0))") ///
	label nonumbers title("Study 2 Summary Statistics" \label{immigrationphonedemos}) replace tex

eststo clear

keep canvasser_id t*_therm_trump_voters t*_trump_voters_diff t*_therm_gop_voters t*_partisan_voters_diff t*_therm_gop_pols  ///
	t*_therm_dem_voters t*_therm_dem_pols t*_therm_trump_oppose t*_therm_agree_imm t*_therm_disagree_imm t*_therm_immigr_diff

rename t1_* *1
rename t0_* *0

foreach var in therm_disagree_imm therm_agree_imm therm_trump_voters {
	gen `var'_change = `var'1 - `var'0
}

// Paired t-test
ttest therm_trump_voters1 = therm_trump_voters0
ttest therm_gop_voters1 = therm_gop_voters0
	
reshape long therm_disagree_imm therm_agree_imm therm_immigr_diff ///
	therm_trump_voters therm_trump_oppose therm_trump_voters_diff therm_gop_voters ///
	therm_dem_voters therm_partisan_voters_diff therm_gop_pols ///
	therm_dem_pols, i(canvasser_id) j(post) // id = unique identifier for each canvasser
	
foreach outcome of varlist therm_disagree_imm therm_agree_imm therm_immigr_diff ///
	therm_trump_voters therm_trump_oppose therm_trump_voters_diff ///
	therm_gop_voters therm_dem_voters therm_partisan_voters_diff ///
	therm_gop_pols therm_dem_pols {
		disp "`outcome'"
		areg `outcome' i.post, a(canvasser_id)
		estimates store `outcome'
}

esttab therm_trump_voters therm_trump_oppose ///
	therm_gop_voters therm_dem_voters ///
	therm_gop_pols therm_dem_pols ///
	therm_disagree_imm therm_agree_imm /// 
	using ///
	../output/immigration_phone_regression_results.tex, replace tex ///
	starlevels(* 0.10 ** 0.05 *** 0.01) se ///
	keep(1.post _cons) coeflabels(1.post "Change" _cons "Const.") ///
	title("Study 2 Regression Results") width(\hsize)  ///
	addnotes("All models include canvasser fixed effects") ///
	mtitle("Trump Supp." "Trump Opp." ///
	"R Voters" "D Voters" ///
	"R Pols" "D Pols" ///
	"Dis. Imm." "Agree Imm." ///
	) nonumbers


